package cn.javacv.gulimall.search.controller;

import cn.javacv.gulimall.common.exception.ErrorCodeEnum;
import cn.javacv.gulimall.common.to.es.SkuEsModel;
import cn.javacv.gulimall.common.utils.R;
import cn.javacv.gulimall.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/search")
public class EsSaveController {

    @Autowired
    private ProductSaveService productSaveService;
    // 上架商品
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModelList){
        try {
            boolean successFlag = productSaveService.productStatusUp(skuEsModelList);
            if (successFlag){
                return R.ok();
            }else {
                return R.error(ErrorCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),ErrorCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
            }
        }catch (Exception e){
            return R.error(ErrorCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),ErrorCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
    }
}
